<template>
  <div class="pd-le-ri">
    <div class="crumbs">
      <el-breadcrumb separator="/">
        <el-breadcrumb-item>
          <el-icon :size="11"><user-filled /></el-icon> 答题排名
        </el-breadcrumb-item>
      </el-breadcrumb>
    </div>
    <div class="container">
      <div style="min-width: 800px; display: flex">
        <el-select v-model="categoryId" class="m-2" placeholder="选择专栏">
          <el-option v-for="item in categoryList.arr" :key="item.id" :label="item.name" :value="item.id" />
        </el-select>
        <div style="margin: 0 20px">
          <el-button type="primary" @click="clickBtn">搜索</el-button>
        </div>
      </div>
      <div style="margin: 20px 0 30px">
        <el-table
          :data="tableData.arr"
          border
          style="width: 100%"
          :stripe="true"
        >
          <el-table-column
            prop="rank"
            label="排名"
            width="240"
          ></el-table-column>
          <el-table-column align="center" label="用户头像" width="200">
            <template v-slot="scope">
              <el-image style="width: 50px; height: 50px" fit="cover" :src="scope.row.userHandImg"
                :preview-src-list="[scope.row.userHandImg]"></el-image>
            </template>
          </el-table-column>
          <el-table-column
            prop="userName"
            label="用户名"
            width="240"
          ></el-table-column>
          <el-table-column
            prop="count"
            label="答题数"
            width="240"
          ></el-table-column>
          <el-table-column
            prop="userId"
            label="答题分数"
            width="240"
          ></el-table-column>
          <el-table-column
            prop="answerTime"
            label="答题时间"
          ></el-table-column>
          <!-- <el-table-column
            prop="wantMomeny"
            label="申请金额"
            width="100"
          ></el-table-column>
          <el-table-column 
            prop="info"
            label="申请进度"
            width="200"
          ></el-table-column> -->
          <!-- <el-table-column label="操作" align="center">
            <template v-slot="scope">
              <el-button
                size="small"
                v-if="scope.row.status == 0"
                type="danger"
                @click="closeAdmin(scope.row.userId)"
                >拒绝提现</el-button
              >
              <el-button
                type="success"
                size="small"
                v-if="scope.row.status == 0"
                @click="openAdmin(scope.row.userId)"
                >同意提现</el-button
              >
              <el-tag class="ml-2" type="success" v-if="scope.row.status == 1"
                >申请通过</el-tag
              >
              <el-tag class="ml-2" type="danger" v-if="scope.row.status == 2"
                >申请失败</el-tag
              >
            </template>
          </el-table-column> -->
        </el-table>
      </div>
      <div style="margin-bottom: 10px">
        <div class="demo-pagination-block">
          <el-pagination
            :page-size="10"
            layout="total, prev, pager, next, jumper"
            :total="total"
            @current-change="handleCurrentChange"
          >
          </el-pagination>
        </div>
      </div>
    </div>
    <!-- <el-dialog v-model="dialogVisible" title="拒绝原因" width="30%">
      <el-form ref="reason" :model="danger" label-width="90px">
        <el-form-item label="拒绝原因">
          <el-input v-model="danger.reason"></el-input>
        </el-form-item>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="dialogVisible = false">取消</el-button>
          <el-button type="primary" @click="refuseUser">确认</el-button>
        </span>
      </template>
    </el-dialog> -->
  </div>
</template>

<script lang="ts">
import { defineComponent, ref, reactive, onMounted } from "vue";
import {
  getWalletList,
  refuseMoney,
  seccussMoney,
} from "../../http/wallet/wallet";
import {
  getCategory,
  getAnswerRank,
  getUserAnswerRecord,
} from "../../http/school/school";
  //   getUserAnswerRecord,
    // // 答题排名
    // getAnswerRank
import { UserFilled } from "@element-plus/icons";

export default defineComponent({
  components: {
    UserFilled,
  },
  setup() {
    let tableData = reactive({
      arr: [],
    });
    let categoryList = reactive({
      arr: [],
    });
    let total = ref();
    let page: number = 1;
    let state = ref("");
    let categoryId = ref("");
    let mangerId = ref("");
    let userId = ref("");
    let danger = reactive({
      reason: "",
      userId: "",
    });
    const dialogVisible = ref(false);

    onMounted(() => {
      getList('');
      getCategoryData();
    });

    const getCategoryData = async () => {
      const res: any = await getCategory({size: 1000, page: 1})
      categoryList.arr = res.data.records
    }

    const getList = async (id:any) => {
      const res: any = await getAnswerRank({id});
      // console.log(res)
      tableData.arr = res.data;
      // total.value = res.total;
    };

    const handleCurrentChange = (e: number) => {
      page = e;
      getList('');
    };

    const clickBtn = () => {
      getList(categoryId.value);
    };

    // const openAdmin = async (e: any) => {
    //   const data = {
    //     userWantMoneyId: e,
    //   };
    //   await seccussMoney(data);
    //   dialogVisible.value = false;
    //   getList();
    // };

    // const refuseUser = async () => {
    //   await refuseMoney(danger);
    //   dialogVisible.value = false;
    //   getList();
    // };

    const closeAdmin = async (e: any) => {
      danger.userId = e;
      dialogVisible.value = true;
    };

    return {
      mangerId,
      tableData,
      total,
      userId,
      dialogVisible,
      state,
      danger,
      categoryId,
      categoryList,
      handleCurrentChange,
      clickBtn,
      // openAdmin,
      closeAdmin,
      // refuseUser,
    };
  },
});
</script>

<style scoped>
</style>
